package com.yjt.sousou.detail;


import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yjt.sousou.R;
import com.yjt.sousou.detail.entity.UserEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：83734
 * 时间：2018/11/25
 * 描述：
 */
public class DispatchingAdapter extends BaseQuickAdapter<UserEntity.DataBean,BaseViewHolder> {
    public DispatchingAdapter(int layoutResId, @Nullable List<UserEntity.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserEntity.DataBean item) {
        helper.setText(R.id.tv_name,item.getUsername());
        helper.setText(R.id.tv_duty,item.getFenzu_name());
        helper.setText(R.id.tv_state,item.getState_name());
      if(item.isSelected()){
          helper.setBackgroundRes(R.id.iv_selected,R.mipmap.dispatch_selected);
      }else {
          helper.setBackgroundRes(R.id.iv_selected,R.mipmap.dispatch_no_selected);
      }
    }
    private List<UserEntity.DataBean> mUsers = new ArrayList<>();
    public String getUserIds(){
        mUsers.clear();
        String ids = "";
        StringBuilder sb = new StringBuilder(ids);
        for (UserEntity.DataBean bean : mData) {
            if(bean.isSelected()){
                sb.append(bean.getId()).append(",");
                mUsers.add(bean);
            }
        }
        if(!sb.toString().equals(""))
            return sb.toString().substring(0,sb.toString().length()-1);
        else return "";
    }
    public List<UserEntity.DataBean> getSelectUsers(){
        return mUsers;
    }
}
